package cn.git.bbs.core.service;

import cn.git.bbs.core.bean.product.*;
import cn.git.bbs.core.dao.product.ColorMapper;
import cn.git.bbs.core.dao.product.ProductMapper;
import cn.git.bbs.core.dao.product.SkuMapper;
import cn.git.bbs.core.service.cms.CmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.swing.text.StyledEditorKit;
import java.util.List;
import java.util.Map;

@Service("cmsService")
public class CmsServiceImpl implements CmsService {
    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private SkuMapper skuMapper;
    public Product selectProductById(Long id) {

        Product product = productMapper.selectByPrimaryKey(id);
        return product;
    }
    @Autowired
    private ColorMapper colorMapper;

    public List<Sku> selectSkuList(Long id) {

        SkuQuery skuQuery = new SkuQuery();
        skuQuery.createCriteria().andProductIdEqualTo(id);
        List<Sku> skus = skuMapper.selectByExample(skuQuery);
        for (Sku sku : skus) {
            Color color = colorMapper.selectByPrimaryKey(sku.getColorId());
            sku.setColor(color);
        }
        return skus;
    }

}
